home *** CD-ROM | disk | FTP | other *** search
- /* BAKCHECK is designed to remind the PC user to back-up their fixed
- disk on a regular interval. It accepts 1 parameter, the number of
- days between regular backups. If not given
- the interval defaults to 30. The program uses a data file stored in
- the root directory named BACKDATE.DAT. The first time the program
- is run, it creates the file. Its total length is 4 bytes - the long
- integer of the results of the time() function the last time a backup
- was performed. This file is updated anytime a backup is started
- from this program. Any backup executed from the command line will
- not update the data file. For compatibility with alternate backup
- systems, the program executes a BAT file called BACKIT.BAT to perform
- the backup. This allows use of a tape unit or floppy system like
- fastback.
-
- Standard usage:
- BAKCHECK 20
-
- This would request a backup 20 days after the last one. The BAKCHECK
- command would typically be entered in the AUTOEXEC.BAT file.
-
- */
-
- #include <process.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <conio.h>
- #include <dos.h>
- #include <errno.h>
-
- main(argc,argv)
-
- int argc;
- char *argv[];
- {
-
- int bperiod;
- int ans;
- int count;
- int fstat;
- int sstat;
-
- unsigned long lbperiod;
- unsigned long newdate;
- unsigned long olddate;
- unsigned long elapsed;
-
- long time();
-
- FILE *datefile;
-
-
- /* Check for parameter, set up backup interval */
-
- bperiod = 0;
- if (argc<1) bperiod=30 ;
- else {
- count = sscanf(argv[1],"%d",&bperiod);
- if (count==EOF || bperiod<1) bperiod=30;
- }
- lbperiod = bperiod * 86400L;
-
-
- /* get last backup date from disk file, create file if not there */
-
- newdate = time();
- datefile = fopen("\\BACKDATE.DAT","r");
- rewind(datefile);
- fstat = fread(&olddate,sizeof(long),1,datefile);
- fclose(datefile);
- if (fstat==NULL)
- {
- printf("BACKDATE.DAT not found, creating...\n");
- datefile = fopen("\\BACKDATE.DAT","w");
- rewind(datefile);
- fstat = fwrite(&newdate,sizeof(long),1,datefile);
- if (fstat==0) printf("\nError in writing backdate.dat.\n");
- fclose(datefile);
- exit(1);
- }
- elapsed = newdate - olddate;
-
- /* If too much time has elapsed, talk to user and suggest backup */
-
- if (elapsed>lbperiod)
- {
- cls();
- printf("The fixed disk hasn't been backed up for more than %d days.\n",bperiod);
- printf("Would you like to back it up now? (Y|N) \n\n");
- ans = getche();
- ans = toupper(ans);
- if (ans=='Y') /* lets do the backup */
- {
- datefile = fopen("\\BACKDATE.DAT","w");
- if (datefile==NULL) printf("\nCouldn't open file.\n");
- rewind(datefile);
- fstat = fwrite(&newdate,sizeof(long),1,datefile);
- if (fstat==0) printf("\nError in writing backdate.dat.\n");
- fclose(datefile);
- sstat=system("BACKIT.BAT");
- }
- else printf("\n\nPlease backup the disk soon.\n\n\n");
- exit(0);
- }
- }
-